﻿namespace VoiceDominion
{
    using System;
    using System.ComponentModel;
    using System.Diagnostics;
    using System.Windows;

    //// http://shortfastcode.blogspot.com/2010/05/how-to-redirect-console-and-debug.html
    public partial class MainWindow : Window
    {
        public MainWindow()
        {
            this.InitializeComponent();

            var writer = new TextBoxStreamWriter(this.DebugConsole);
            Console.SetOut(writer);
            Console.WriteLine("Redirecting console output to the text box. Feel free to close this window, the application will not exit. Clicking the icon in the tray will show this window again.");

            Debug.Listeners.Add(new TextWriterTraceListener(Console.Out));
            Debug.WriteLine("Redirecting debug output to the text box");
        }

        protected override void OnStateChanged(EventArgs e)
        {
            if (this.WindowState == WindowState.Minimized)
            {
                this.Hide();
            }

            base.OnStateChanged(e);
        }

        protected override void OnClosing(CancelEventArgs e)
        {
            base.OnClosing(e);
            e.Cancel = true;
            this.Hide();
        }
    }
}
